import 'package:flutter/material.dart';
import 'package:flutter_xyf/pages/component/app_bar/index.dart';
import 'package:flutter_xyf/utils/navigator_util.dart';

import 'sliver_appbar.dart';

class SliverDemo extends StatelessWidget {
  const SliverDemo({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: MyAppBar(title: 'sliver_demo'),
      body: CustomScrollView(
        slivers: [
          SliverToBoxAdapter(
            child: ElevatedButton(
              onPressed: () {
                NavigatorUtil.pushPage(
                    context: context, targetPage: SliverBarDemo());
              },
              child: Text('到sliverAppbar'),
            ),
          ),
          SliverGrid(
              delegate: SliverChildBuilderDelegate((context, index) {
                return Container(
                  height: 100,
                  color: Colors.primaries[index % Colors.primaries.length],
                );
              }, childCount: 10),
              gridDelegate:
                  SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 4)),
          SliverFixedExtentList(
              // 限制子元素的高度
              delegate: SliverChildListDelegate([
                FlutterLogo(
                  size: 200,
                )
              ]),
              itemExtent: 100),
          SliverList(
              delegate: SliverChildListDelegate([
            FlutterLogo(
              size: 200,
            )
          ])),
          SliverFillViewport(
              // 每个元素填满整个视窗
              delegate: SliverChildListDelegate([Text('fas'), Text('fas')])),
          SliverList(delegate: SliverChildBuilderDelegate((context, index) {
            return Container(
              height: 100,
              color: Colors.primaries[index % Colors.primaries.length],
            );
          }))
        ],
      ),
    );
  }
}
